module.exports = function ($scope, $modalInstance,$resource, $modal, item, toaster){
    // $scope.opeinfo = item; 
    $scope.opeinfo = {
      'id' : ''
    };
    if (item) {
        $scope.opeinfo.id = item.id;
    }
    $scope.getArea = function(){
        $resource('/api/as/puc/authorizedt/findAddressCodeList', {}, {}).save({}, function(res){
            if(res.errcode === 0){
                $scope.provincelist = res.data
                console.log($scope.provincelist);
            }else{
                toaster.error({title: '', body: res.errmsg});
            }
        });
    }
    $scope.getArea();
    $scope.changeprovince = function(obj){
        console.log(obj);
        $scope.opeinfo.code = obj.code;
        $scope.opeinfo.city_id = obj.id;
    }
    var array1 = [];
    $scope.change = function(obj){
        console.log(obj);
        if (obj.mark == true) {
          array1.push(obj);
        } else {
          for (var i = 0; i < array1.length; i++){
            if (obj.id == array1[i].id) {
              array1.splice(i,1);
            }
          }
        }
        console.log(array1);
        var arr1 = [];
        var arr2 = [];
        for (var i = 0; i < array1.length; i++) {
          arr1.push(array1[i].code);
          console.log(arr1);
          $scope.opeinfo.city = arr1.join(',');
          console.log($scope.opeinfo.code);
          arr2.push(array1[i].id);
          $scope.opeinfo.city_id = arr2.join(',');
        }
    }

    //保存
    $scope.save = function (){
        console.log($scope.opeinfo);
        if ($scope.opeinfo.role_pwxuid != '' || $scope.opeinfo.city != '' || $scope.opeinfo.city_id != ''
            || $scope.opeinfo.num != '' || $scope.opeinfo.mark != '' ) {
              $resource('/api/ac/mc/merchantUserTaopiaoRoleService/updateTaopiaoShopApplyYes', {}, {}).save($scope.opeinfo, function(res){
                if(res.errcode === 0){
                    toaster.success({title: '', body: '保存成功'});
                    $modalInstance.close();
                }else{
                    toaster.error({title: '', body: res.errmsg});
                }
            });
        } else {
            toaster.error({title: '', body: '信息填写不完整'});
        }
        
    }

    //取消
    $scope.cancel = function () {
        $modalInstance.dismiss('cancel');
    }
};